package org.bonorsoft.common.dingapi;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRoleGetroleRequest;
import com.dingtalk.api.response.OapiRoleGetroleResponse;
import com.taobao.api.ApiException;
import org.bonorsoft.common.constant.URLConstant;

public class DingdingRole {

    public static String getRole(Long id) {
        String result = "";
        try {
            DingTalkClient client = new DefaultDingTalkClient(URLConstant.GET_ROLE);
            OapiRoleGetroleRequest req = new OapiRoleGetroleRequest();
            req.setRoleId(id);
            OapiRoleGetroleResponse rsp = client.execute(req, AccessTokenUtil.getToken());
            JSONObject obj = JSON.parseObject(rsp.getBody());
            result = obj.getString("role");
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return result;
    }
}
